package alkaid.eis.schedule.controller;

import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import alkaid.eis.common.web.BaseMapper;
import alkaid.eis.schedule.domain.JobInfo;
import alkaid.eis.schedule.domain.JobLog;

/**
 * 任务信息映射器
 * 
 * @author Lucky Yang
 * @since 0.0.1
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface JobLogMapper extends BaseMapper<JobLogDto, JobLog> {
    JobLogMapper INST = Mappers.getMapper(JobLogMapper.class);

    /**
     * 额外处理: 设置任务信息
     * 
     * @param dto
     * @param entity
     */
    @AfterMapping
    default void setJobInfo(@MappingTarget JobLogDto dto, JobLog entity) {
        JobInfo jobInfo = entity.getJobInfo();

        dto.setJobDesc(String.format("%s:%s:%s", jobInfo.getClassName(), jobInfo.getMethodName(), jobInfo.getRemark()));
    }

}
